package User;

import Base.ResourceTest;
import EntityBuilder.RenterBuilder;
import com.huawei.translate.model.Renter;
import com.huawei.translate.vo.user.UpdateCategoryRequest;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.UUID;

@RunWith(SpringRunner.class)
public class When_user_update_category extends ResourceTest {

    @Test
    public void should_return_bad_request_when_renter_not_exist() {
        UpdateCategoryRequest request = new UpdateCategoryRequest();
        request.setId("notExist");
        request.setCategory("category");
        ResponseEntity response = this.testRestTemplate.postForEntity("/api/user/category", request,Object.class);
        Assert.assertEquals(HttpStatus.BAD_REQUEST,response.getStatusCode());
    }

    @Test
    public void should_return_ok_when_request_is_valid() {
        Renter renter = new RenterBuilder(renterRepository)
                .WithAppKey("Test")
                .WithAppSecret(UUID.randomUUID().toString())
                .WithCategory("MicroSoftHubCategory")
                .Build();

        UpdateCategoryRequest request = new UpdateCategoryRequest();
        request.setId(renter.getId());
        request.setCategory("category");
        ResponseEntity response = this.testRestTemplate.postForEntity("/api/user/category", request,Object.class);

        Assert.assertEquals(HttpStatus.OK,response.getStatusCode());
        Assert.assertEquals(renterRepository.findById(renter.getId()).getCategory(),request.getCategory());
    }
}
